package com.dzm.content.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 作者：Dzm
 * 时间：2024-09-13-19:02
 * 功能：
 */

@Data
@Component
@ConfigurationProperties(prefix = "aliyun.oss")
public class OssProperties implements InitializingBean {
    private String endpoint;
    private String accessKey;
    private String accessSecret;
    private String bucketName;

    public static String ENDPOINT;
    public static String ACCESS_KEY;
    public static String ACCESS_SECRET;
    public static String BUCKET_NAME;
    @Override
    public void afterPropertiesSet() throws Exception {
        ENDPOINT = endpoint;
        ACCESS_KEY = accessKey;
        ACCESS_SECRET = accessSecret;
        BUCKET_NAME = bucketName;
    }

    @Bean
    public OSS ossClient() {
        return new OSSClientBuilder().build(endpoint, accessKey, accessSecret);
    }
}
